#include "fcntl.h"
#include "unistd.h"
#include "stdio.h"
#include "errno.h"
#include "string.h"
int main(int argc, char const *argv[])
{
    // 打开文件
    int fd1 = open("test/app_buffer_test.c", O_RDONLY);
    printf("fd1: %d\n", fd1);
    if (fd1 == -1)
    {
        //printf("open file error\n");
        //printf("open file error: %d\n", errno);
        //printf("open file error: %s\n", strerror(errno));
        perror("open file error");
        return 0;
    }
    printf("fd1打开成功\n");

    int fd2 = open("test/test.c", O_RDWR | O_CREAT, 0666);
    printf("fd2: %d\n", fd2);
    if (fd2 == -1)
    {
        perror("open file error");
        return 0;
    }

    char buffer[128] = {0};
    ssize_t real_len = 0;

    while ((real_len = read(fd1, buffer, sizeof(buffer))) > 0)
    {
        //printf("%.*s", (int)real_len, buffer);
        write(fd2, buffer, real_len);
        // 控制台的文件描述符:   
        // 标准输入0  标准输出1  标准错误输出2
        write(STDOUT_FILENO, buffer, real_len);
    }

    close(fd1);

    return 0;
}

// open close write read
